{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "49c37288-09ca-4bb4-bccb-746655187456",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入操作数x： 2\n",
      "请输入操作数y： 2\n",
      "请输入操作符： -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.0 - 2.0 = 0.0\n"
     ]
    }
   ],
   "source": [
    "right=True\n",
    "x = float(input(\"请输入操作数x：\"))\n",
    "y = float(input(\"请输入操作数y：\"))\n",
    "op = str(input(\"请输入操作符：\")) \n",
    "if(op=='+'):r = x + y\n",
    "elif (op=='-'):r = x - y\n",
    "elif (op=='*'):r = x * y\n",
    "elif (op=='/'):\n",
    "    if(y==0):\n",
    "        print(\"分母=0，零除异常！\")\n",
    "        right=False\n",
    "    else: r = x / y\n",
    "elif (op=='%'):\n",
    "    if(y==0):\n",
    "        print(\"分母=0，零除异常！\")\n",
    "        right=False\n",
    "    else: r = x % y\n",
    "if right: print(x,op,y,'=',r)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35c725fe-e22f-4a70-a681-89f90311ef1f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
